<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>上传文件</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="../../layuiadmin/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="../../layuiadmin/style/admin.css" media="all">
</head>
<body>
<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-header">上传文件</div>
                <div class="layui-card-body">
                    <div class="layui-upload">
                        <button type="button" class="layui-btn layui-btn-normal" id="test-upload-change">选择文件</button>
                        <button type="button" class="layui-btn" id="test-upload-change-action">开始上传</button>
                    </div>
                </div>
            </div>
            <div class="layui-card">
                <div class="layui-card-header">上传结果</div>
                <div class="layui-card-body" id="upload-result">

                </div>
            </div>
        </div>
    </div>
</div>
</body>

<script src="../../layuiadmin/layui/layui.js"></script>
<script src="../../jquery-3.4.1/jquery.min.js"></script>
<script type="text/javascript">

    layui.config({
        base: '../../layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'upload'], function() {
        var $ = layui.jquery
            , upload = layui.upload;
        var localTest = layui.sessionData('test');

        //选完文件后不自动上传
        upload.render({
            elem: '#test-upload-change'
            ,url: 'http://'+localTest.address+'/http/file/upload'
            ,auto: false
            ,accept:"file"
            //,multiple: true
            ,bindAction: '#test-upload-change-action'
            ,done: function(res){
                console.log(res)
                var text = " <p >上传成功</p>" +
                    "<p >文件ID:       "+res.data.file_id+"</p>\n" +
                    "<p >文件内容Hash:       "+res.data.content_hash+"</p>\n" +
                    "<p >交易Hash:     "+res.data.tx_hash+"</p>\n" +
                    "<p >等待进块</p>"
                $("#upload-result").html(text)
            }

        });
    });

</script>
</html>